<?php
class RolesController extends Exts_Controller_SecureAction
{

    public function listAction()
    {
        $roleModel = new Exts_Models_Roles();
        $query = $roleModel->select();
        $this->view->paginator = new Exts_Paginator( $query, $this->_page, $this->view );
    }

    public function createAction()
    {
        $form = new Exts_Forms_Role();
        if ( $this->getRequest()->isPost() ) {
            $postData = $this->getRequest()->getParams();
            if( $form->isValid( $postData ) ) {
                $bind = $form->getValues();
                $roleModel = new Exts_Models_Roles();
                 //Validamos que el headoffice no exista con el mismo nombre

                try {
                    $id = $roleModel->save( $bind['name'] );
                    return $this->_redirect('/roles/list' );
                } catch ( Exception $e )  {
                    $this->_helper->flashMessenger()
                        ->addMessage( 'Ocurrio un error revise los datos del formulario' );
                }
            }
            $form->populate( $form->getValues());
        }
        $this->view->form = $form;
    }
}